package fr.vahren.processing.picking;

import processing.core.PApplet;
import processing.core.PVector;
import fr.vahren.processing.Main;
import fr.vahren.processing.entity.Atom;
import fr.vahren.processing.entity.Entity;

public class PickerDist {
	private PApplet parent;

	public PickerDist(Main main) {
		parent = main;
	}

	public Entity pick(int mouseX, int mouseY) {
		Entity choice = null;
		float dist = 0, choiceDist = Main.ATOM_SIZE * 2.5f;
		for (Entity e : ((Main) parent).getEntities()) {
			if (e instanceof Atom) {

				dist = PApplet.dist(parent.screenX(e.x(), e.y(), e.z()),
						parent.screenY(e.x(), e.y(), e.z()), mouseX, mouseY);
				if (dist < Main.ATOM_SIZE * 2 && dist < choiceDist) {
					choice = e;
					choiceDist = dist;
				}
			}

		}
		return choice;
	}

}
